module.exports = {
  setCookie: (cookie) => {
    if (typeof (cookie) == "object") {
      for (const key in cookie) {
        if (Object.hasOwnProperty.call(cookie, key)) {
          const value = cookie[key];
          let cookieRecord = lebeta_cookieRecord()
          cookieRecord.push(key)
          cookieRecord = [...new Set(cookieRecord)]
          localStorage.lebeta_cookieRecord = JSON.stringify(cookieRecord)
          document.cookie = key + "=" + value;
        }
      }
    }
  },
  getCookie: (key) => {
    const getCookie = (name) => document.cookie.match(`[;\s+]?${name}=([^;]*)`)?.pop();
    return getCookie(key)
  },
  clearCookie: () => {
    let cookieRecord = lebeta_cookieRecord()
    cookieRecord.forEach(item => {
      this.removeCookie(item)
    })
  },
  removeCookie: (key) => {
    if (this.getCookie(key))
      this.setCookie(key, '', -1)
  }
}

let lebeta_cookieRecord = () => {
  return localStorage.lebeta_cookieRecord ? JSON.parse(localStorage.lebeta_cookieRecord) : []
}